package com.baimifan.renovation;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baimifan.renovation.tools.statusBar;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener{
    private Activity login;
    private Float w, h, widthPixels, heightPixels;
    private RelativeLayout login_rl;
    private EditText phone, code;
    private View login_view,login_view2;
    private FrameLayout login_fl;
    private TextView login_tag, login_count,login_btn;
    private LinearLayout bottom_ll;
    private ImageView login_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        login = LoginActivity.this;
        statusBar.setColor(login, Color.parseColor("#FF602C"));
        getDisplay();
        init();
        setParams();
    }

    private void init () {
        login_rl = (RelativeLayout) findViewById(R.id.login_rl);
        phone = (EditText) findViewById(R.id.login_phone);
        login_view = findViewById(R.id.login_view);
        login_view2 = findViewById(R.id.login_view2);
        code = (EditText) findViewById(R.id.login_code);
        login_fl = (FrameLayout) findViewById(R.id.login_fl);
        login_tag = (TextView) findViewById(R.id.login_tag);
        login_count = (TextView) findViewById(R.id.login_count);
        login_btn = (TextView) findViewById(R.id.login_btn);
        bottom_ll = (LinearLayout) findViewById(R.id.login_bottm_ll);
        login_back = (ImageView) findViewById(R.id.login_back);

        login_btn.setOnClickListener(this);
    }

    private void setParams(){
        LinearLayout.LayoutParams params_rl = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (h * 44));
        login_rl.setLayoutParams(params_rl);

        LinearLayout.LayoutParams params_phone = new LinearLayout.LayoutParams((int) (w * 240), (int) (h * 24));
        params_phone.setMargins(0,(int) (h * 69), 0 , 0);
        params_phone.gravity = Gravity.CENTER;
        phone.setLayoutParams(params_phone);

        LinearLayout.LayoutParams params_view = new LinearLayout.LayoutParams((int) (w * 270), 1);
        params_view.setMargins(0,(int) (h * 15), 0 , 0);
        params_view.gravity = Gravity.CENTER;
        login_view.setLayoutParams(params_view);
        LinearLayout.LayoutParams params_view2 = new LinearLayout.LayoutParams((int) (w * 270), 1);
        params_view2.setMargins(0,(int) (h * 11), 0 , 0);
        params_view2.gravity = Gravity.CENTER;
        login_view2.setLayoutParams(params_view2);

        LinearLayout.LayoutParams params_fl = new LinearLayout.LayoutParams((int) (w * 240), ViewGroup.LayoutParams.WRAP_CONTENT);
        params_fl.setMargins(0,0, 0, 0);
        params_fl.gravity = Gravity.CENTER;
        login_fl.setLayoutParams(params_fl);

        FrameLayout.LayoutParams params_code = new FrameLayout.LayoutParams((int) (w * 147), (int) (h * 24));
        params_code.setMargins(0,(int)(h*36), 0, 0);
        code.setLayoutParams(params_code);

        FrameLayout.LayoutParams params_tag = new FrameLayout.LayoutParams((int) (w * 83), (int) (h * 32));
        params_tag.setMargins((int)(w*157), (int)(h*32), 0, 0);
        login_tag.setLayoutParams(params_tag);
        login_count.setLayoutParams(params_tag);

        LinearLayout.LayoutParams params_login = new LinearLayout.LayoutParams((int)(w*266),(int)(h*44));
        params_login.setMargins(0,(int) (h * 45), 0 , 0);
        params_login.gravity = Gravity.CENTER;
        login_btn.setLayoutParams(params_login);

        LinearLayout.LayoutParams params_bottom = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params_bottom.setMargins(0,(int) (h * 256), 0 , 0);
        params_bottom.gravity = Gravity.CENTER;
        bottom_ll.setLayoutParams(params_bottom);

        RelativeLayout.LayoutParams params_back = new RelativeLayout.LayoutParams((int)(w*19.7),(int)(h*19.7));
        params_back.setMargins((int)(w*16), 0, 0, 0);
        params_back.addRule(RelativeLayout.CENTER_VERTICAL);
        login_back.setLayoutParams(params_back);

    }


    private void getDisplay() {
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        widthPixels = Float.valueOf(metrics.widthPixels);
        heightPixels = Float.valueOf(metrics.heightPixels);
        w = widthPixels / 360;
        h = heightPixels / 640;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.login_btn:
                Intent intent = new Intent(login, HomeActivity.class);
                login.startActivity(intent);
                break;
        }
    }
}
